package se.teamstat.client.gui.admin.player;

import se.teamstat.client.dto.EntityDTO;
import se.teamstat.client.dto.PlayerDTO;
import se.teamstat.client.gui.admin.EntityPanel;

import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.form.VType;
import com.gwtext.client.widgets.layout.FormLayout;

public class AddPlayerPanel extends AddPanel implements EntityPanel {
	
	private TextField firstName;
	private TextField lastName;
	private TextField email;
	
	private AddPlayerPanel() {
		init();
	}
	
	public static Panel createPanel() {
		Panel panel = new AddPlayerPanel();
		return panel;
	}
	
	public EntityDTO getEntity() {
		PlayerDTO player = new PlayerDTO();
		player.setFirstName(firstName.getValueAsString());
		player.setLastName(lastName.getValueAsString());
		player.setEmail(email.getValueAsString());
		return player;
	}
	
	
	
	private void init() {
		setTitle("Spelare");
		setId("add_player_item");
		setLayout(new FormLayout());
		setAutoHeight(true);
		setPaddings(10);

		firstName = new TextField("First Name", "first", 230);
		firstName.setAllowBlank(false);
		add(firstName);

		lastName = new TextField("Last Name", "last", 230);
		add(lastName);

		email = new TextField("Email", "email", 230);
		email.setVtype(VType.EMAIL);
		add(email);
		
		Button saveButton = new Button("Save", listener);
		Button cancelButton = new Button("Cancel");
		
		add(saveButton);
		add(cancelButton);
		
	}

	@Override
	public EntityPanel getActiveTab() {
		return this;
	}
	
}
